package com.kaifamiao.month04.day05;

import java.util.Scanner;

public class StackTest {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个括号字符串：");
        String str = in.next();
        System.out.println(isLegal(str));
    }

    public static boolean isLegal(String str){
        Stack stack = new Stack();
        char[] strings = str.toCharArray();
        for (char s : strings) {
            if (s == '(') {
                stack.push(s);
            } else if (s == ')') {
                if (stack.pop() == null)
                    return false;
            }
        }
        return stack.isEmpty();
    }
}
